package com.zr.d_c.serviceimpl;

import com.zr.d_c.dao.AdminDao;
import com.zr.d_c.dao.SellerDao;
import com.zr.d_c.daoimpl.AdminDaoImpl;
import com.zr.d_c.daoimpl.SellerDaoImpl;
import com.zr.d_c.service.AdminService;

import net.sf.json.JSONArray;
import net.sf.json.JSONObject;

public class AdminServiceImpl implements AdminService{
	AdminDao admin = new AdminDaoImpl();
	SellerDao seller = new SellerDaoImpl();
	@Override
	public JSONObject getAllCustomer(int start, int pageSize) {
		// TODO Auto-generated method stub
		JSONObject customer = new JSONObject();
		customer.put("total", admin.selectCustomerCount());
		customer.put("rows", JSONArray.fromObject(admin.selectAllCustomer(start, pageSize)));
		return customer;
	}

	@Override
	public JSONObject getCustomer(int start, int pageSize, String searchcname) {
		// TODO Auto-generated method stub
		JSONObject customer = new JSONObject();
		customer.put("total", admin.selectcustomerCount(searchcname));
		customer.put("rows", JSONArray.fromObject(admin.selectCustomerByCname(start, pageSize, searchcname)));
		return customer;
	}

	@Override
	public JSONObject getAllSeller(int start, int pageSize) {
		// TODO Auto-generated method stub
		JSONObject seller = new JSONObject();
		seller.put("total", admin.selectSellerCount());
		seller.put("rows", JSONArray.fromObject(admin.selectAllSeller(start, pageSize)));
		return seller;
	}

	@Override
	public JSONObject getSeller(int start, int pageSize, String searchsname) {
		// TODO Auto-generated method stub
		JSONObject seller = new JSONObject();
		seller.put("total", admin.selectSellerCount(searchsname));
		seller.put("rows", JSONArray.fromObject(admin.selectSellerBySname(start, pageSize, searchsname)));
		return seller;
	}

	@Override
	public int cancelSellerDeleteInSeller(int sid) {
		// TODO Auto-generated method stub
		return seller.cancleSellerDeleteBySid(sid);
	}

	@Override
	public int cancelSellerDeleteInUser(int uid) {
		// TODO Auto-generated method stub
		return admin.cancleSellerDeleteByUid(uid);
	}

	public JSONObject getAllCustomerToResetUpsw(int start, int pageSize) {
		// TODO Auto-generated method stub
		JSONObject customer = new JSONObject();
		customer.put("total", admin.selectCustomerCountToResetUpsw());
		customer.put("rows", JSONArray.fromObject(admin.selectAllCustomerToResetUpsw(start, pageSize)));
		return customer;
	}

	@Override
	public JSONObject getCustomerToResetUpsw(int start, int pageSize, String searchcname) {
		// TODO Auto-generated method stub
		JSONObject customer = new JSONObject();
		customer.put("total", admin.selectcustomerCountToResetUpsw(searchcname));
		customer.put("rows", JSONArray.fromObject(admin.selectCustomerByCnameToResetUpsw(start, pageSize, searchcname)));
		return customer;
	}

	@Override
	public JSONObject getAllSellerToResetUpsw(int start, int pageSize) {
		// TODO Auto-generated method stub
		JSONObject seller = new JSONObject();
		seller.put("total", admin.selectSellerCountToResetUpsw());
		seller.put("rows", JSONArray.fromObject(admin.selectAllSellerToResetUpsw(start, pageSize)));
		return seller;
	}

	@Override
	public JSONObject getSellerToResetUpsw(int start, int pageSize, String searchsname) {
		// TODO Auto-generated method stub
		JSONObject seller = new JSONObject();
		seller.put("total", admin.selectSellerCountToResetUpsw(searchsname));
		seller.put("rows", JSONArray.fromObject(admin.selectSellerBySnameToResetUpsw(start, pageSize, searchsname)));
		return seller;
	}

}
